//
//  ViewController.swift
//  Swift3_懒加载
//
//  Created by kingseraphs on 25/04/2017.
//  Copyright © 2017 kingseraphs. All rights reserved.
//

import UIKit

class ViewController: UIViewController {

//    var label: DemoLabel?
    
    
    ///懒加载(常用写法)
    /**
        1.延迟创建
        2.最大的好处 -> 免除解包的烦恼
     */
//    lazy var label: DemoLabel = DemoLabel()
    
    ///完整写法
    /**
        1.不常用
        2.懒加载就是一个闭包
        a.{}代表代码块
        b.()代表执行
     */
    var label = {() -> DemoLabel in
        let l = DemoLabel()
        return l
    }()
    
    override func viewDidLoad() {
        super.viewDidLoad()
        // Do any additional setup after loading the view, typically from a nib.
        
        setUpUI()
    }
    
    func setUpUI() -> () {
//        label = DemoLabel()
        
        view.addSubview(label)
//        
//        label?.text = "foo"
//        label?.sizeToFit()
//        label?.center = view.center
        
        label.text = "baz"
        label.sizeToFit()
        label.center = view.center
    }
}

